package cool.mtc.base.plugin.generator.code.controller;

import cool.mtc.base.plugin.generator.code.model.dto.DbColumnDTO;
import cool.mtc.base.plugin.generator.code.model.form.TemplateParamForm;
import cool.mtc.base.plugin.generator.code.model.query.DbColumnQuery;
import cool.mtc.base.plugin.generator.code.model.query.DbTableQuery;
import cool.mtc.base.plugin.generator.code.service.CodeGeneratorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 明河
 */
@Tag(name = "代码生成")
@RestController
@RequestMapping("minghe/api/code_generate")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CodeGeneratorController {
    private final CodeGeneratorService codeGeneratorService;

    @Tag(name = "代码生成")
    @Operation(summary = "获取数据库的所有表名")
    @GetMapping("db/table/list")
    public List<String> listTable(DbTableQuery query) {
        return codeGeneratorService.listTable(query);
    }

    @Tag(name = "代码生成")
    @Operation(summary = "获取数据库表的所有列名")
    @GetMapping("db/column/list")
    public List<DbColumnDTO> listColumn(DbColumnQuery query) {
        return codeGeneratorService.listColumn(query);
    }

    @Tag(name = "代码生成")
    @Operation(summary = "代码生成")
    @PostMapping("generate")
    public void codeGenerate(@RequestBody @Validated TemplateParamForm form) {
        codeGeneratorService.codeGenerate(form);
    }
}
